<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="__TPL__/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__TPL__/frame/static/css/style.css">
    <link rel="icon" href="__TPL__/frame/static/image/code.png">
</head>
<body class="body">

<form class="layui-form" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">菜单名</label>
        <div class="layui-input-inline">
            <input type="text" name="text" placeholder="请输入菜单名" lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-inline">
            <select name="pid">
                <option>作为一级菜单</option>
                {volist name="menus" id="vo"}
                <option value="{$vo.id}">{$vo.text}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">图标</label>
            <div class="layui-input-block">
                <input type="text" name="icon" placeholder="请输入图标" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
                <input type="text" name="href" placeholder="请输入链接地址" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-inline">
            <input type="text" name="describe" placeholder="请输入描述信息" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="text" name="sort" placeholder="请输入排序数字" lay-verify="number" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="add_submit">新增菜单</button>
        </div>
    </div>
</form>

<script src="__TPL__/frame/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;
        form.on('submit(add_submit)', function (data) {
            $.ajax({
                url: '{:url("Auth/addMenuPost")}',
                type: 'post',
                data: data.field,
                dataType: 'json',
                success: function (data) {
                    if (data.code === 1) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000})
                    }
                }
            });
            return false;
        })
    });
</script>
</body>
</html>